package com.xxwy.unionfind.practice.main;


import com.xxwy.unionfind.*;

import java.util.Random;

/**
 * @author xxwy
 */
public class Main {

    private static double testUF(UF uf, int m) {
        int size = uf.getSize();
        Random random = new Random();
        long startTime = System.nanoTime();
        for (int i = 0; i < m; i++) {
            int a = random.nextInt(size);
            int b = random.nextInt(size);
            uf.unionElements(a, b);

        }
        for (int i = 0; i < m; i++) {
            int a = random.nextInt(size);
            int b = random.nextInt(size);
            uf.isConnected(a, b);

        }
        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }

    public static void main(String[] args) {
        int size = 10000000;
        int m = 10000000;
       // UnionFind1 unionFind1 = new UnionFind1(size);
        UnionFind2 unionFind2 = new UnionFind2(size);
        UnionFind31 unionFind31 = new UnionFind31(size);
        UnionFind32 unionFind32 = new UnionFind32(size);
        UnionFind33 unionFind33 = new UnionFind33(size);
        UnionFind34 unionFind34 = new UnionFind34(size);

       // System.out.println("UnionFind1 " + testUF(unionFind1, m)+"s");
        System.out.println("UnionFind2 " + testUF(unionFind2, m)+"s");
        System.out.println("UnionFind31 size优化 " + testUF(unionFind31, m)+"s");
        System.out.println("UnionFind32 rank优化 " + testUF(unionFind32, m)+"s");
        System.out.println("UnionFind33 压缩优化 " + testUF(unionFind33, m)+"s");
        System.out.println("UnionFind34 压缩优化 " + testUF(unionFind34, m)+"s");

    }
}
